<style media="screen">
  .tab-view{
    padding:1%;
  }

</style>
<style media="screen">
.masthead.segment {
  min-height: auto;
  padding: 1em 0em;
}
</style>
<div class="ui container">
  <div class="ui divider">
    <%= flash_tag(:error, :class => 'ui error message transition flash-notice') %>
    <%= flash_tag(:success, :class => 'ui success message transition flash-notice') %>
  </div>
  <script type="text/javascript">
  $('.flash-notice').fadeOut(3000);

  </script>
  <div class="ui doubling four column grid">
    <div class="column">
      <h2 class="ui icon header">
        <i class="circular user icon"></i>
        个人中心<span id="editUserInfo" style="font-size:12px" class="ui mini button">修改资料</span>
        <div style="font-size:15px">账户余额：<span id="balance_amount"><%= @user.balance.amount %></span></div>
        <div class="ui buttons">
          <div id="withDrawBtn" class="ui mini red basic button">
            提现处理
          </div>
          <a href="/personal/bank_cards" id="myBankBtn" class="ui mini blue basic button">
            我的银行卡
          </a>
        </div>

      </h2>
    </div>
    <div class="column">


      <br>  <br>
      <p>手机：<%= @user.mobile %></p>
      <p>密码：<span id="updatePassBtn" class="ui tiny basic red button"><%= session[:valid] ? "设置" : "修改" %>密码</span></p>
      <p>用户名：<%= @user.username %>
      </p>
      <p>我的签名：<%= @user.personal_title %></p>



    </div>
    <div class="column">
      <br>  <br>
      <p>手机：<%= @user.mobile %></p>
      <p>昵称：<%= @user.fake_name %></p>


      <p>真实姓名：<%= @user.real_name %></p>
    </div>
    <div class="column">  <br>  <br>
      <p>邮箱：<%= @user.email %></p>
        <p>最近资料更新于：<%= @user.updated_at.strftime("%Y-%m-%d %H:%M:%S") %></p>
      <p>注册于：<%= @user.created_at.strftime("%Y-%m-%d %H:%M:%S") %></p>
    </div>
  </div>


  <div class="ui divider">

  </div>
  <div class="ui">
    <div class="ui top attached tabular menu">
      <a class="active item" data-tab="first">我的收支</a>
      <a class="item" data-tab="second">我的订单</a>

    </div>
    <div class="ui bottom attached active tab tab-view" data-tab="first">
      <% if @bills.length > 0 %>
        <div class="ui vertically divided grid">

        <% @bills.each do |bill| %>
        <div class=" doubling five column row">
          <div class="column">
            账单类型：<%=bill.cash_type %>
          </div>
          <div class="column">
            金额：<%=bill.amount %>
          </div>
          <div class="column">
            详细信息：<%=bill.info %>
          </div>
          <div class="column">
            状态：<%= bill_status(bill.status) %>
          </div>
          <div class="column">
            发起于：<%=bill.created_at.strftime("%Y-%m-%d %H:%M:%S") %>
          </div>
        </div>
        <% end %>
      </div>
      <% else %>


      <div class="ui container">
        <br>
          <h3>哦，您还没有流水呢～</h3>
          <h4>——请接着<a href="/products">分享</a>赚钱</h4>
          <h4>——或者，在有余额的情况下，<a href="/products">提现</a></h4>
          <br><br><br>
      </div>
      <div class="">

      </div>
      <% end %>
    </div>
    <div class="ui bottom attached tab tab-view" data-tab="second">
      <div class="ui vertically divided grid">



      <% if @orders.length > 0 %>

        <% @orders.each do |order| %>
        <div class="doubling six column row">
          <div class="column" style="word-break:break-all;">
            编号：<%= order.id %>
          </div>

          <div class="column"  style="word-break:break-all;">
            商品：
            <ul>
              <% order.order_products.each do |order_product| %>
                <% if order_product.product %>

                <li><a href="/products/<%= order_product.product.id %>">
                <%= order_product.product.product_model_type %></a>　&times;
                 <%= order_product.counter %></li>
                 <% else %>
                    <li>该商品已经下架</li>
                 <% end %>
              <% end %>
            </ul>

          </div>
          <div class="column">
              下单时间：<%= order.created_at.strftime("%Y-%m-%d %H:%M:%S") %>
          </div>
          <div class="column">
              状态：<%= order.status %>
              <% if order.status == "正在进行中" %>
                ——请耐心等待我们与您联系
              <% end %>
              <% if order.status == "已完成" %>
                ——最终交易总额为:<%= order.amount %>万元
              <% end %>

          </div>
          <div class="column">
              状态更新：<%= order.updated_at.strftime("%Y-%m-%d %H:%M:%S") %>
          </div>
        </div>
        <% end %>
      </div>balance_amount
      <% else %>
      <div class="ui container">
        <br>
          <h3>哦，您还没有下单呢～</h3>
          <h4>——请接着<a href="/products">随意逛逛</a></h4>
          <br><br><br>
      </div>
      <div class="">

      </div></div>
      <% end %>
    </div>

  </div>
</div>
<div class="ui container">
  <div class="ui modal" id="editUserModal">
    <div class="header">
      修改个人资料
    </div>
    <div class="content">
    <% personal = User.find(@user.id) %>
    <% form_tag url('personal/update'), id: 'userInfoForm', method: "post", class: "ui form" do %>
      <div class="ui container">
        <div class="ui header">
          <br/>
          <div class="field">
            <label for="mobile">手机:</label>
            <input type="text" id="valid_mobile" name="mobile" value="<%= @user.mobile %>" placeholder=''><br/>
          </div>
          <div class="field">
            <label for="mobile">邮箱:</label>
            <input type="text" id="valid_mobile" name="email" value="<%= @user.email %>" placeholder=''><br/>
          </div>
          <div class="field">
            <label for="mobile">用户名:</label>
            <input type="text" id="valid_mobile" name="username" value="<%= @user.username %>" placeholder=''><br/>
          </div>
          <div class="field">
            <label for="mobile">昵称:</label>
            <input type="text" id="valid_mobile" name="fake_name" value="<%= @user.fake_name %>" placeholder=''><br/>
          </div>
          <div class="field">
            <label for="mobile">真实姓名:</label>
            <input type="text" id="valid_mobile" name="real_name" value="<%= @user.real_name %>" placeholder=''><br/>
          </div>
          <div class="field">
            <label for="mobile">签名:</label>
            <textarea name="personal_title" rows="8" value="" cols="80">
              <%= @user.personal_title %>
            </textarea>
            <br/>
          </div>

        </div>
      </div>
    <% end %>
    </div>
    <div class="actions">
      <button  type="button" class="ui black deny button">
        取消
      </button>
      <button id="saveUserInfoBtn" type="button" class="ui positive  button">
        保存
      </button>
    </div>

  </div>
  <div class="ui dimmer">
    <div class="content">
      <div class="center">
        <h2 class="ui inverted icon header">
          <i class="progress icon"></i>
          <span id="loadMessage">正在保存更改......<span>
        </h2>
      </div>
    </div>
  </div>

</div>

  <div class="ui modal" id="updatePass">
    <i class="close icon"></i>
  <div class="header">
      <%= session[:valid] ? "设置" : "修改" %>密码
  </div>
  <div class="content">
      <% form_tag url('personal/updatepass'), id: 'updatepassForm', method: "post", class: "ui form" do %>
        <% if session[:valid] == nil %>
          <div class="field">
            <label for="old_password">您的旧密码:</label>
            <input id="old_pass"  type="password" id="valid_mobile" name="old_password" value="" placeholder=''><br/>
          </div>
        <% end %>

        <div class="field">
          <label for="pass">新密码:</label>
          <input type="password" id="new_pass" name="password" value="" placeholder=''><br/>
        </div>
        <div class="field">
          <label for="pass_confirm">新密码确认:</label>
          <input type="password" id="new_pass_confirm" name="password_confirmation"  value="" placeholder=''><br/>
        </div>
      <% end %>
      <script type="text/javascript">

      </script>

  </div>
  <div class="actions">
    <div class="two fluid ui  buttons">
      <div class="ui cancel red basic  button">
        <i class="remove icon"></i>
        取消
      </div>
      <div class="ui ok green basic  button">
        <i class="checkmark icon"></i>
        保存
      </div>
    </div>
  </div>
  <div class="ui dimmer">
    <div class="content">
      <div class="center">
        <h2 class="ui inverted icon header">
          <i class="progress icon"></i>
          <span id="loadMessage">正在保存更改......<span>
        </h2>
      </div>
    </div>
  </div>
  </div>


  <div class="ui modal" id="withRequireModal">
    <i class="close icon"></i>
  <div class="header">
    发起提现请求
  </div>
  <div class="content">
      <% form_tag url('personal/require_withdraw'), id: 'withdrawForm', method: "post", class: "ui form" do %>
        <div class="field">
          <label for="amount">提现金额(最低提现金额为100元):</label>
          <input style="width:30%" type="number" min='1' id="withdraw_amount" name="amount" value="1" placeholder='最低提现金额为100元'>
          <span style="font-size: x-large;font-weight:bolder;">00元</span><br/>
          &nbsp;&nbsp;&nbsp;提现确认：
          <span id="withdrawShow" style="font-size: x-large;font-weight:bolder;">100</span>元
        </div>
        <div class="field">
          <label>请选择要提现的银行</label>
          <div name="category" class="ui floating dropdown labeled search icon button category">
            <input type="hidden" name="bank_card_id" value="<%=@user.bank_cards[0] ? @user.bank_cards[0].id : "" %>">
              <i class="book icon"></i>
              <span class="text"></span>
              <div class="menu">
                <% @user.bank_cards.each do |bank_card| %>
                <div class="item" data-value="<%= bank_card.id %>"><%= bank_card.card_number %>(<%= bank_card.bank_real_name %>)----<%= bank_card.bank_address %></div>
                <% end %>
              </div>
            </div>
            <!-- <input type="hidden" name="category" value="" id="fcategory"> -->
        </div>
        <script type="text/javascript">
        $('.ui.dropdown.category')
          .dropdown({
            allowAdditions: false,
            onChange: function(value, text, $selectedItem) {
              $("#fcategory").val(value);
            }
          })
          ;
        </script>

      <% end %>


  </div>
  <div class="actions">
    <div class="two fluid ui  buttons">
      <div class="ui cancel red basic  button">
        <i class="remove icon"></i>
        取消
      </div>
      <div class="ui ok green basic  button">
        <i class="checkmark icon"></i>
        发送提现请求
      </div>
    </div>
  </div>
  <div class="ui dimmer">
    <div class="content">
      <div class="center">
        <h2 class="ui inverted icon header">
          <i class="progress icon"></i>
          <span id="loadMessage">正在提交您的请求......<span>
        </h2>
      </div>
    </div>
  </div>
  </div>




<script type="text/javascript">
  $('.menu .item').tab();
  $('#editUserInfo').click(function(){
    $('#editUserModal').modal({
    closable  : true,
    onDeny    : function(){
      return true;
    },
    onApprove : function() {
      $('#editUserModal').dimmer("show");
      $('#userInfoForm').submit();
      return false;
    }
  }).modal('show');

  });
  $("#updatePassBtn").click(function(){
    $("#updatePass").modal(
      {
      closable  : true,
      onDeny    : function(){
        return true;
      },
      onApprove : function() {
        $("#updatePass").dimmer("show");
        var pass = $("#new_pass").val();
        var pass_confirm = $("#new_pass_confirm").val();
        var old_pass = $("#old_pass").val();
        if (old_pass == '') {
          alert('旧密码不能留空');
          $("#updatePass").dimmer("hide");
          return false;
        }
        if (new_pass == '' || pass_confirm=="") {
          alert('所有项都不得为空');
          $("#updatePass").dimmer("hide");
          return false;
        }
        if (pass != pass_confirm) {
          alert('两次密码不一致');$("#updatePass").dimmer("hide");
          return false;
        }
        $('#updatepassForm').submit();
        return false;
      }
    }

    ).modal('show');
  });


  $("#withdrawForm").submit(function(){
    var require = parseInt($("#withdraw_amount").val());
    var amount = parseInt($("#balance_amount").html());
    if (require == NaN || require < 1) {
      alert("请输入至少1的数字：输入不合理");
      return false;
    }

    if ((require*100) > amount) {
      alert("账户余额不足以支持您的提现请求");
      return false;
    }

    alert("提现请求已经发起，3到5个工作日到账！");
    $('#withRequireModal').dimmer("show");
    return true;
  });
  $("#withDrawBtn").click(function(){
    $.get('personal/bank_exists',{stamp: Math.random()},function(result){
      if (result == "1") {
        $("#withRequireModal").modal({
          onApprove: function(){

            $('#withdrawForm').trigger("submit");

          }
        }).modal("show");
      }else{
        alert('你还没有提供银行卡信息');
        return false;
      }


    });

  });
  $("#withdraw_amount").change(function(){
    var val = $(this).val();
    $("#withdrawShow").html(parseFloat(val)*100);
  })


</script>
